Imports System.Web.UI.WebControls
Namespace HBBSoft.Pivot
    Friend NotInheritable Class DisplayCellSetTable
        Dim _CellSet As CellSet
        Dim _ept As ePivotTableControl

        Public Sub New(ByRef cs As CellSet, ByRef ept As ePivotTableControl)
            _CellSet = cs
            _ept = ept
        End Sub

        Public Function ToTable() As Table
            Dim t As New Table
            Dim tr As TableRow
            Dim row As Integer
            Dim col As Integer
            Dim dc As New DisplayCell_DataCell

            If _CellSet.Cells.Count = 0 Then
                t = New Table
            Else
                For row = 0 To _CellSet.Cells.Count / _CellSet.ColumnCount - 1
                    tr = New TableRow

                    For col = 0 To _CellSet.ColumnCount - 1
                        If (row * _CellSet.ColumnCount + col) Mod 13 = 0 Then    'Demo Code
                            dc.Cell = _CellSet.Cells(row * _CellSet.ColumnCount + col)
                            tr.Cells.Add(dc.GetDataCell(_ept, True))
                        Else 'Demo Code
                            dc.Cell = _CellSet.Cells(row * _CellSet.ColumnCount + col)
                            tr.Cells.Add(dc.GetDataCell(_ept, False))
                        End If 'Demo Code


                    Next

                    t.Rows.Add(tr)
                Next
            End If

            Return t
        End Function
    End Class
End Namespace